package gregicadditions.machines;

import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.ColourMultiplier;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.texture.TextureUtils;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import gregtech.api.GTValues;
import gregtech.api.render.Textures;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.ArrayUtils;

public class CrateRenderer implements TextureUtils.IIconRegister {
	private final String basePath;

	@SideOnly(Side.CLIENT)
	private TextureAtlasSprite sideSprite;

	public CrateRenderer(String basePath) {
		this.basePath = basePath;
		Textures.iconRegisters.add(this);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void registerIcons(TextureMap textureMap) {
		this.sideSprite = textureMap.registerSprite(new ResourceLocation(GTValues.MODID, "blocks/" + basePath));
	}

	public void render(CCRenderState renderState, Matrix4 translation, int baseColor, IVertexOperation[] pipeline) {

		IVertexOperation[] basePipeline = ArrayUtils.add(pipeline, new ColourMultiplier(baseColor));

		for (EnumFacing renderSide : EnumFacing.VALUES) {
			Textures.renderFace(renderState, translation, basePipeline, renderSide, Cuboid6.full, sideSprite);
		}
	}

	@SideOnly(Side.CLIENT)
	public TextureAtlasSprite getParticleTexture() {
		return sideSprite;
	}
}